﻿using System;
using System.Collections.Specialized;
using System.Configuration;
using System.Configuration.Provider;
using System.Collections.Generic;
using System.Web;
using Netkk.Common.Models;

namespace Netkk.Data.Provider
{
    public abstract class DataProvider : ProviderBase
    {
        protected string ConnectionString
        {
            get;
            private set;
        }

        protected string ConnectionStringName
        {
            get;
            private set;
        }

        public override void Initialize(string name, NameValueCollection config)
        {
            base.Initialize(name, config);

            if (config != null)
            {
                ConnectionStringName = config["connectionStringName"];
                config.Remove("connectionStringName");
            }

            if (!String.IsNullOrEmpty(ConnectionStringName))
            {
                ConnectionString = ConfigurationManager.ConnectionStrings[ConnectionStringName].ConnectionString;
                if (!String.IsNullOrEmpty(ConnectionString) && ConnectionString.Substring(0, 2) == "~/")
                {
                    ConnectionString = HttpContext.Current.Server.MapPath(ConnectionString);
                }
            }
        }

        public abstract IEnumerable<User> SelectAllUsers();
        public abstract void SaveUser(User user);
        public abstract void DeleteUser(User user);

        public abstract IEnumerable<UserRole> SelectAllRoles();

        public abstract IEnumerable<Link> SelectAllLinks();
        public abstract void SaveLink(Link link);
        public abstract void DeleteLink(Link link);

        public abstract IEnumerable<Appointment> SelectAllAppointments();
        public abstract void SaveAppointment(Appointment appointment);
        public abstract void DeleteAppointment(Appointment appointment);

        public abstract IEnumerable<Content> SelectAllContents();
        public abstract void DeleteContent(Content content);
        public abstract void SaveContent(Content content);

        public abstract IEnumerable<Download> SelectAllDownloads();
        public abstract void DeleteDownload(Download download);
        public abstract void SaveDownload(Download download);


        public abstract IEnumerable<News> SelectAllNews();
        public abstract void SaveNews(News appointment);
        public abstract void DeleteNews(News appointment);
    }
}